{php include wl_template('common/header');}
<!--<span class="price" style="display:none;">0.01</span>-->
<ul class="nav nav-tabs">
	<li {if $op == 'base'}class="active"{/if}><a href="{php echo web_url('store/selflogistics', array('op' => 'base'))}">基本设置</a></li>
	{if $checkfunction['status']}	
	<li {if $op == 'display'}class="active"{/if}><a href="{php echo web_url('store/selflogistics', array('op' => 'display'))}">送货上门管理</a>
	</li>
	{/if}
</ul>
{if $op == 'base'}
	
	<div class="panel panel-default">
	<div class="panel-body table-responsive" style="padding: 0px;">
		<div class="main_bd">
        <div class="plugins_wrp">
            <dl>
                <dd>
                    <ul id="js_plugins">
						<li class="item_wrp" style="width: 100%;">
							<div class="plugin_item">
								<!--<div class="plugin_icon"><img src="{TG_URL_WRES}images/function/homedelivery.png" style="cursor:pointer;"></div>-->
								<div  id="link-icon1" class="plugin_icon" >
									<div id="link-icon" style="display:none;width:100%;height:100%;position:absolute;background-color:rgba(0,0,0,0.3);cursor:pointer;">
										<img src="{TG_URL_WRES}images/3.svg"style="position:absolute;width:60%;left:20%;">
									</div>
									<img src="{TG_URL_WRES}images/function/homedelivery.png" style="cursor:pointer;">
								</div>
								<div class="plugin_status">
									<i class="access"></i>
									<span class="status_txt">
										{if $checkfunction['status']}	
											
										<div id="renewal" style="font-size:20px;margin-top:-30px;width: 60px;height:60px;border-radius:50%;font-weight:900;background-color:#ff5466;color:white;margin-right: -25px;text-align:center;line-height:60px;cursor:pointer;">续费</div>										
								
										<span style="display:block;margin-left:-70px;color:#888;font-size:14px;">截止日期：{php echo date('Y-m-d', $checkfunction['endtime'])}</span>
										
										{else}
										
										<div id="buyDaifu" style="font-size:20px;margin-top:-20px;width: 60px;height:60px;border-radius:50%;font-weight:900;background-color:#ff5466;color:white;margin-right: -25px;text-align:center;line-height:60px;cursor:pointer;">购买</div>
										{/if}
									</span>
								</div>
								<div class="plugin_content">
									<h3 class="title">{$_W['page']['title']}</h3>
									<p class="desc" style="    width: 100%;">
										启用送货上门功能后，能自定义设置商品送货上门运费。支持与快递运费、自提、送货时间共同搭配使用。
									</p>
								</div>
							</div>
						</li>
					</ul>
                </dd>
            </dl>
        </div>
    </div>
	</div>
</div>
	{/if}
	{if $op == 'display'}
	<form action="" method="post">
	<div class="main panel panel-default">
	    <div class="panel-body table-responsive">
	        <table class="table table-hover">
	            <thead class="navbar-inner">
	                <tr>
	                    <th style="width:50px;">ID</th>
	                    <th>名称</th>
	                  
	                    <th>状态</th>
	                    <th>操作</th>
	                </tr>
	            </thead>
	            <tbody>
	                {loop $list $item}
	                <tr>
	                    <td>{$item['id']}</td>
	                    <td>{$item['dispatchname']}</td>
	                    
	                    <td><label class='label  label-default {if $item['enabled']==1}label-info{/if}' >{if $item['enabled']==1}显示{else}隐藏{/if}</label></td>
	                    <td style="text-align:left;">
	                       <a href="{php echo web_url('store/selflogistics',array('op' =>'post','id' => $item['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="修改"><i class="fa fa-pencil"></i></a>
	                      <a href="{php echo web_url('store/selflogistics',array('op' =>'delete','id' => $item['id']))}" class="btn btn-default btn-sm" onclick="return confirm('确认删除此送货上门方式?')" title="删除"><i class="fa fa-times"></i></a>
	                    </td>
	                </tr>
	                {/loop}
					
	                <tr>
	                    <td colspan='8'>
	                        <a class='btn btn-default' href="{php echo web_url('store/selflogistics',array('op' =>'post'))}"><i class='fa fa-plus'></i> 添加送货上门方式</a>
	                        <input type="hidden" name="token" value="{$_W['token']}" />
	                    </td>
	                </tr>
				
	            </tbody>
	        </table>
	    </div>
	</div>
	</form>
	{/if}
	{if $op == 'post'}
		<div class="main">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
        <input type="hidden" name="id" value="{$dispatch['id']}" />
        <div class="panel panel-default">
          
             
			<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>派送名称</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='dispatchname' name="dispatchname" class="form-control" value="{$dispatch['dispatchname']}" />
                    </div>
              </div>
					<div class="form-group dispatch2" >
                         <label class="col-xs-12 col-sm-3 col-md-2 control-label">送货上门运费设置<br>(设置时按购物车总金额由低到高设定)</label>
                    <div class="col-sm-9 col-xs-12">
                   
                        <table>
                            <thead>
                            <tr>
                                <th style="width:320px;">购物车金额(小于等于)</th>
                                <th style="width:120px;">费用</th>
                              
                                <th></th>
                            </tr>
                            </thead>
                            <tbody id='tbody-delivery'>
                                {loop $dispatch_delivery $row}
                                   {php $deliverys = random(16);}
                                   <tr class='{$deliverys}'>
 <input type="hidden" name="deliverys[]" value="{$deliverys}" />
<td class="text-center"><input type="text" value="{$row['cart']}" class="form-control" name="cart[{$deliverys}]" style="width:100px;"></td>
<td class="text-center"><input type="text" value="{$row['cost']}" class="form-control" name="cost[{$deliverys}]" style="width:100px;"></td>
<td><a href='javascript:;' onclick='$(this).parent().parent().remove()'><i class='fa fa-remove'></i></td>
</tr> 
                                {/loop}
                            </tbody>
                        </table>
                         
                        <a class='btn btn-default' style='margin-top:10px;' href="javascript:;" onclick='addDelivery(this)'><span class="fa fa-plus"></span> 新增运费</a>
                        
                    </div>
                    </div>
            
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否启用</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class='radio-inline'>
                            <input type='radio' name='enabled' value=1 {if $dispatch['enabled']==1}checked{/if} /> 是
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='enabled' value=0 {if $dispatch['enabled']==0}checked{/if} /> 否
                        </label>
                    </div>
                </div>
            <div class="form-group"></div>
            <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" onclick="return formcheck()" />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                    </div>
            </div>
            </div>
    </form>
</div>
<style type='text/css'>
    .province { float:left; position:relative;width:150px; height:35px; line-height:35px;border:1px solid #fff;}
    .province:hover { border:1px solid #f7e4a5;border-bottom:1px solid #fffec6; background:#fffec6;}
    .province .cityall { margin-top:10px;}
    .province ul { list-style: outside none none;position:absolute;padding:0;background:#fffec6;border:1px solid #f7e4a5;display:none;
    width:auto; width:300px; z-index:999999;left:-1px;top:32px;}
    .province ul li  { float:left;min-width:60px;margin-left:20px; height:30px;line-height:30px; }
 </style>
 
	


{/if}
<script language='javascript'>
    $(function(){
        
        $(':radio[name=dispatchtype]').click(function(){
            var val = $(this).val();
            $(".dispatch0,.dispatch1,.dispatch2").hide();
            $(".dispatch" + val ).show();
        })
      
        $("select[name=express]").change(function(){
              var obj = $(this);
                var sel = obj.find("option:selected");
                $(":input[name=expressname]").val(sel.data("name"));
        });
        {if !empty($dispatch['express'])}
           $("select[name=express]").val("{$dispatch['express']}");
        {/if}

   
        $('.province').mouseover(function(){
              $(this).find('ul').show();
        }).mouseout(function(){
              $(this).find('ul').hide();
        });
        
        $('.cityall').click(function(){
            var checked = $(this).get(0).checked;
            var citys = $(this).parent().parent().find('.city');
            citys.each(function(){
                $(this).get(0).checked = checked;
            });
            var count = 0;
            if(checked){
                count =  $(this).parent().parent().find('.city:checked').length;
            }
            if(count>0){
               $(this).next().html("(" + count + ")")    ;
            }
            else{
                $(this).next().html("");
            }
        });
        $('.city').click(function(){
            var checked = $(this).get(0).checked;
            var cityall = $(this).parent().parent().parent().parent().find('.cityall');
          
            if(checked){
                cityall.get(0).checked = true;
            }
            var count = cityall.parent().parent().find('.city:checked').length;
            if(count>0){
               cityall.next().html("(" + count + ")")    ;
            }
            else{
                cityall.next().html("");
            }
        });    
      
    });
    function getCurrents(withOutRandom){
        var citys = "";
        $('.citys').each(function(){
             var crandom = $(this).prev().val();
             if(withOutRandom && crandom==withOutRandom){
                 return true;
             }
             citys+=$(this).val();
        });
        return citys;
    }
    function addCarrier(btn){
        $(btn).button('loading');
        $.ajax({
            url:"{php echo $this->createWebUrl('area',array('op'=>'tpl1'))}",
            dataType:'json',
            success:function(json){
                $(btn).button('reset');
                 $('#tbody-carriers').append(json.html);
            }
        });
    }
	function addDelivery(btn){
        $(btn).button('loading');
        $.ajax({
            url:"{php echo web_url('store/selflogistics',array('op' =>'tpl2'))}",
            dataType:'json',
            success:function(json){
                $(btn).button('reset');
                 $('#tbody-delivery').append(json.html);
            }
        });
    }
    var current = '';
    {if $op=='yunfei'}
    function addArea(btn){
        $(btn).button('loading');
        $.ajax({
            url:"{php echo $this->createWebUrl('area',array('op'=>'tpl'))}",
            dataType:'json',
            success:function(json){
                $(btn).button('reset');
                current = json.random;
              
                $('#tbody-areas').append(json.html);
                
                 clearSelects();
                
                $("#modal-areas").modal();
                var currents = getCurrents();
                currents = currents.split(';');
                var citystrs = "";
               
                $('.city').each(function(){
                    var parentdisabled =false;
                    for(var i in currents){
                        if(currents[i]!='' && currents[i]==$(this).attr('city')){
                            $(this).attr('disabled',true);
                            $(this).parent().parent().parent().parent().find('.cityall').attr('disabled',true);
                        }
                    }
                  
                });
                $('#btnSubmitArea').unbind('click').click(function(){
                      $('.city:checked').each(function(){              
                         citystrs+= $(this).attr('city') +";";
                      });
                      $('.' + current + ' .cityshtml').html(citystrs);
                      $('.' + current + ' .citys').val(citystrs);
                })
            }
        })
    }
    {else}
    function addArea(btn){
        $(btn).button('loading');
        $.ajax({
            url:"{php echo $this->createWebUrl('area',array('op'=>'tpl','limit'=>'limit'))}",
            dataType:'json',
            success:function(json){
                $(btn).button('reset');
                current = json.random;
              
                $('#tbody-areas').append(json.html);
                
                 clearSelects();
                
                $("#modal-areas").modal();
                var currents = getCurrents();
                currents = currents.split(';');
                var citystrs = "";
                 var priv = "";
                $('.city').each(function(){
                    var parentdisabled =false;
                    for(var i in currents){
                        if(currents[i]!='' && currents[i]==$(this).attr('city')){
                            $(this).attr('disabled',true);
                            $(this).parent().parent().parent().parent().find('.cityall').attr('disabled',true);
                        }
                    }
                  
                });
                $('#btnSubmitArea').unbind('click').click(function(){
                		$('.cityall:checked').each(function(){              
                         priv+= $(this).attr('cityall') +";";
                      });
                      $('.city:checked').each(function(){              
                         citystrs+= $(this).attr('city') +";";
                      });
                      $('.' + current + ' .cityshtml').html(priv);
                      $('.' + current + ' .citys').val(priv);
                })
            }
        })
    }
    {/if}
    function clearSelects(){
          $('.city').attr('checked',false).removeAttr('disabled');
         $('.cityall').attr('checked',false).removeAttr('disabled');
         $('.citycount').html('');
    }
    function editArea(btn){
        current = $(btn).attr('random');
        clearSelects();
        var old_citys = $(btn).prev().val().split(';');
      
                
        $('.city').each(function(){
            var parentcheck = false;
            for(var i in old_citys){
                if(old_citys[i]==$(this).attr('city')){
                    parentcheck = true;
                    $(this).get(0).checked = true;
                    break;
                }
            }
            if(parentcheck){
                $(this).parent().parent().parent().parent().find('.cityall').get(0).checked=  true;
            }
        });
        
        $("#modal-areas").modal();
        var citystrs = '';
        $('#btnSubmitArea').unbind('click').click(function(){
                   $('.city:checked').each(function(){              
                     citystrs+= $(this).attr('city') +";";
                   });
                   $('.' + current + ' .cityshtml').html(citystrs);
                   $('.' + current + ' .citys').val(citystrs);
        })
           var currents = getCurrents(current);
                currents = currents.split(';');
                var citys = "";
                $('.city').each(function(){
                    var parentdisabled =false;
                    for(var i in currents){
                        if(currents[i]!='' && currents[i]==$(this).attr('city')){
                            $(this).attr('disabled',true);
                            $(this).parent().parent().parent().parent().find('.cityall').attr('disabled',true);
                        }
                    }
                  
                });
    }
    function formcheck() {
        if ($("#dispatchname").isEmpty()) {
            Tip.focus("dispatchname", "请填写派送方式名称!", "top");
            return false;
        }
        return true;
    }
	var linkicon=document.getElementById("link-icon");
		var linkicon2=document.getElementById("link-icon1");
		
		linkicon2.onmouseleave = function () {
			linkicon.style.setProperty( 'display', 'none' );
		}
		
		linkicon2.onmouseover = function () {
			linkicon.style.setProperty( 'display', 'block' );
		}
		
		linkicon.onclick=function (ev) {
			document.getElementById('detailimg').src='{TG_URL_WRES}images/function/shsm.jpg';
			document.getElementById("detailname").innerHTML = "送货上门";
			document.getElementById("detailshow").style.setProperty("display","block");
		}
</script>



{php include wl_template('common/footer');}